package ebcs.database.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ebcs.database.bean.BsGoal;
import ebcs.database.bean.BsNeedInfor;
import ebcs.database.bean.BsNeedInforData;
import ebcs.database.bean.BsNeedInforExample;
import ebcs.database.bean.BsNeedStage;
import ebcs.database.bean.BsNeedTime;
import ebcs.database.bean.BsOnlineNeed;
import ebcs.database.bean.BsSaleNeed;
import ebcs.database.bean.BsUserInfor;
import ebcs.database.bean.BsUserNeedRel;
import ebcs.database.bean.BsUserNeedRelExample;
import ebcs.database.bean.BsUserNeedRelExample.Criteria;
import ebcs.database.bean.FaceToFace;
import ebcs.database.bean.NeedConversion;
import ebcs.database.bean.RpUserReportBean;
import ebcs.database.bean.RpUserTaskNeedBean;
import ebcs.database.mybatis.dao.BsNeedInforMapper;
import ebcs.database.mybatis.dao.BsNeedInforMapperSelf;
import ebcs.database.mybatis.dao.BsUserInforMapper;
import ebcs.database.mybatis.dao.BsUserNeedRelMapper;
import ebcs.database.mybatis.dao.FaceToFaceMapper;
import ebcs.database.mybatis.dao.RpUserReportMapper;
import ebcs.database.mybatis.dao.RpUserTaskNeedMapper;
import ebcs.database.service.BsUserNeedServiceImp;
import ebcs.scan.common.utils.StringUtil;

@Service
public class BsUserNeedServiceImpl implements BsUserNeedServiceImp
{
	@Autowired
	private BsUserNeedRelMapper userNeedRelDao;
	 
	@Autowired
	private RpUserReportMapper reportDao;
	
	@Autowired
	private RpUserTaskNeedMapper taskDao;
	
	@Autowired
	private BsNeedInforMapper needDao;
	
	@Autowired
	private BsUserInforMapper userDao;
	
	@Autowired
	private BsNeedInforMapperSelf needSelfDao;
	
	@Autowired
	private FaceToFaceMapper faceDao;
	
	
	
	@Override
	public boolean regUserNeedRel(BsUserNeedRel record) {
		int i = userNeedRelDao.insert(record);
		if(i>0){
			return true;
		}
		return false;
	}
	//
	@Override
	public List<RpUserReportBean> searchUserNeedInfor(RpUserReportBean record) {		
		return reportDao.selectReport(record);
	}  
	//
	@Override
	public List<RpUserReportBean> selectReportCount(RpUserReportBean record) {		
		return reportDao.selectReportCount(record);
 	}
	@Override
	public List<RpUserTaskNeedBean> selectTaskNeedList(RpUserTaskNeedBean condition) {
		List<RpUserTaskNeedBean> rsList = taskDao.selectTaskNeedList(condition);
		return rsList;
	}
	
	@Override
	public List<RpUserTaskNeedBean> selectNoTaskNeedList(RpUserTaskNeedBean condition) {
		List<RpUserTaskNeedBean> rsList = taskDao.selectNoTaskNeedList(condition);
		return rsList;
	}
	@Override
	public int selectUserTaskTime(RpUserTaskNeedBean condition) {
		return taskDao.selectUserTaskTime(condition);
	}
	@Override
	public int deleteUserNeedInfor(String rouid) {
		return this.userNeedRelDao.deleteUserNeedInfor(rouid);
	} 
  
	@Override
	public int addNeedInfor(BsNeedInfor record) { 
		return this.needDao.insert(record);
	}
	@Override
	public List<BsNeedInfor> selectNeedInforByNeedNoAndTeamNo(BsNeedInfor record) {
		BsNeedInforExample example = new BsNeedInforExample();
		ebcs.database.bean.BsNeedInforExample.Criteria criteria = example.createCriteria();
		criteria.andNeedNoEqualTo(record.getNeedNo());
		criteria.andProTeamNoEqualTo(record.getProTeamNo());		
		return this.needDao.selectByExample(example);
 	}
	@Override
	public List<RpUserTaskNeedBean> selectTaskNeedListByTeamNo(RpUserTaskNeedBean condition) {
		List<RpUserTaskNeedBean> rsList = taskDao.selectTaskNeedListByTeamNo(condition);
		return rsList;
	}
	@Override
	public List<RpUserTaskNeedBean> selectTaskNeedListByGroupNo(RpUserTaskNeedBean condition) {
		List<RpUserTaskNeedBean> rsList = taskDao.selectTaskNeedListByGroupNo(condition);
		return rsList;
	}
	@Override
	public List<RpUserReportBean> searchUserHistoryNeedInfor(RpUserReportBean reportConditon) {
		
		return reportDao.selectHistoryNeedInfor(reportConditon);
	}
	
	@Override
	public List<RpUserReportBean> selectHistoryNeedInfor(RpUserReportBean reportConditon) {
		
		return reportDao.selectHistoryNeed(reportConditon);
	}
	
	
	@Override
	public int updateNeedInforById(BsNeedInfor need) {
		BsNeedInforExample example = new BsNeedInforExample();
		BsNeedInforExample.Criteria criteria = example.createCriteria();
		criteria.andRouidEqualTo(need.getRouid());		
		return this.needDao.updateByExample(need, example);
	}
	
	@Override
	public int updateNeedNoRelByNeedId(BsNeedInfor bean) {
	 
 		return this.needSelfDao.updateNeedNoRelByNeedId( bean);
	}
	@Override
	public List<BsNeedInfor> selectNeedInforList(BsNeedInfor need) {
		
		BsNeedInforExample example = new BsNeedInforExample();
		BsNeedInforExample.Criteria criteria = example.createCriteria();
		criteria.andProTeamNoEqualTo(need.getProTeamNo());
		if(StringUtil.isNotEmpty(need.getNeedName())){
			criteria.andNeedNoLike(need.getNeedName());
		}
		if(StringUtil.isNotEmpty(need.getNeedName())){
			BsNeedInforExample.Criteria orCriteria = example.createCriteria();
			orCriteria.andNeedNameLike(need.getNeedName());
			example.or(orCriteria);
		}
		
		return this.needDao.selectByExample(example);
		
	}
	@Override
	public List<BsNeedInfor> selectNeedInfor(BsNeedInfor need) {
		if (StringUtil.isEmpty(need.getCurrentPage())) {
			need.setStartRow("0");
			need.setEndRow(need.getPageSize()==null?"200":need.getPageSize());
		} else {
			need.setStartRow((Integer.parseInt(need.getCurrentPage()) - 1) * Integer.parseInt(need.getPageSize()) + "");
			need.setEndRow((Integer.parseInt(need.getCurrentPage())) * Integer.parseInt(need.getPageSize()) + "");
		}
		return this.needSelfDao.selectNeedInfor(need);
	}
	
	@Override
	public List<BsNeedTime> selectNeedTimeList(BsUserInfor user) {
		return this.needSelfDao.selectNeedTime(user) ;
	}
	@Override
	public int closeUserNeedRel(String rouid) {
		// TODO Auto-generated method stub
		return this.userNeedRelDao.closeUserNeedRel(rouid);
	}
	@Override
	public List<BsNeedInfor> selectNoPassNeedByRouid(String rouid) {
		return this.needDao.selectNoPassNeedByRouid(rouid);
	}
	@Override
	public int updateStateByRouid(String rouid, String state) {
		String rydc = needDao.selectRydcByRouid(rouid);
		if(StringUtil.isEmpty(rydc)) {
			rydc = "0";
		}
		return this.needDao.updateStateByRouid(rydc, rouid, state);
	}
	@Override
	public int updateSignByRouid(String rouid, String sign) {
		return this.needDao.updateSignByRouid(rouid, sign);
	}
	@Override
	public List<BsNeedInforData> selectByBsNeedInforData(BsNeedInforData bsNeedInforData) {
		return this.needDao.selectByBsNeedInforData(bsNeedInforData);
	}
	@Override
	public int insertNeedInforData(List<BsNeedInforData> list) {
		// TODO Auto-generated method stub
		return this.needDao.insertNeedInforData(list);
	}
	@Override
	public int updateNeedInforDataByNeedNo(BsNeedInforData bsNeedInforData) {
		// TODO Auto-generated method stub
		return this.needDao.updateNeedInforDataByNeedNo(bsNeedInforData);
	}
	@Override
	public int deleteNeedInforData() {
		// TODO Auto-generated method stub
		return this.needDao.deleteNeedInforData();
	}
	@Override
	public List<BsNeedInfor> selectNeedInforDetail(BsNeedInfor need) {
		// TODO Auto-generated method stub
		return this.needSelfDao.selectNeedInforDetail(need);
	}
	@Override
	public int reStartUserNeedRel(String rouid) {
		// TODO Auto-generated method stub
		return this.userNeedRelDao.reStartUserNeedRel(rouid);
	}
	@Override
	public BsUserInfor getProTeamNo(String userNo) {
		// TODO Auto-generated method stub
		return this.userDao.getProTeamNo(userNo);
	}
	@Override
	public void updateNeedInfor(BsNeedInfor needInfor) {
		this.needDao.updateNeedInfor(needInfor);
	}

	@Override
	public List<BsUserNeedRel> selectByNeedId(String needId) {
		// TODO Auto-generated method stub
		return userNeedRelDao.selectByNeedId(needId);
	}
	@Override
	public boolean deleteInfor(String needId) {
		// TODO Auto-generated method stub
		return userNeedRelDao.deleteInfor(needId);
	}
	@Override
	public List<RpUserReportBean> searchReviewJob(RpUserReportBean reportConditon) {
		// TODO Auto-generated method stub
		return reportDao.searchReviewJob(reportConditon);
	}
	@Override
	public void updateReportStateByRouId(BsUserNeedRel bsUserNeedRel) {
		// TODO Auto-generated method stub
		userNeedRelDao.updateReportStateByRouId(bsUserNeedRel);
	}
	@Override
	public List<RpUserReportBean> searchHistoryJob(RpUserReportBean req) {
		// TODO Auto-generated method stub
		return reportDao.searchHistoryJob(req);
	}
 
 	@Override
	public List<BsNeedInfor> selectBankResolve(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectBankResolve(req);
	}

	@Override
	public List<BsNeedInfor> selectBankSummary() {
		// TODO Auto-generated method stub
		return needSelfDao.selectBankSummary();
	}

	@Override
	public int doUpdateJianKong(BsNeedInfor req) {
		BsNeedInforExample example = new BsNeedInforExample();
		BsNeedInforExample.Criteria criteria = example.createCriteria();
		criteria.andRouidEqualTo(req.getRouid());
		// TODO Auto-generated method stub
		return this.needDao.doUpdateJianKong(req, example);

	}
 @Override
	public List<BsNeedInfor> selectSoftwareSummary(BsNeedInfor req) {
		// TODO Auto-generated method stub
		 return needSelfDao.selectSoftwareSummary(req);
	}
	@Override
	public List<BsNeedInfor> selectBankResolvePage(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectBankResolvePage(req);
	}
	@Override
	public int selectBankResolvePageCount(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectBankResolvePageCount(req);
	}
	@Override
	public int selectNeedInforDetailPageCount(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectNeedInforDetailPageCount(req);
	}
	@Override
	public List<BsNeedInfor> selectNeedInforDetailPage(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectNeedInforDetailPage(req);
	}
	@Override
	public List<RpUserReportBean> searchUserNeedInforPage(RpUserReportBean reportConditon) {
		// TODO Auto-generated method stub
		return reportDao.selectReportPage(reportConditon);
	}
	@Override
	public int searchUserNeedInforPageCount(RpUserReportBean reportConditon) {
		// TODO Auto-generated method stub
		return reportDao.selectReportPageCount(reportConditon);
	}
	@Override
	public List<BsNeedInfor> searchNeedInforList(BsNeedInfor needInfor) {
		// TODO Auto-generated method stub
		return needDao.searchNeedInforList(needInfor);
	}
	@Override
	public List<RpUserReportBean> searchTeamReviewJob(RpUserReportBean record) {
		// TODO Auto-generated method stub
		return reportDao.searchTeamReviewJob(record);
	}
	@Override
	public List<BsNeedInfor> searchTeamNeedInforList(BsNeedInfor needInfor) {
		// TODO Auto-generated method stub
		return needDao.searchTeamNeedInforList(needInfor);
	}
 
	@Override
	public List<BsSaleNeed> selectBsSaleNeedById(String needid) {
		// TODO Auto-generated method stub
		return  needSelfDao.selectBsSaleNeedById(needid);
	}
	public void updatahandProstate(String rouid) { 
		userNeedRelDao.updatahandlProstate(rouid);
	}
	
	@Override
	public List<BsUserNeedRel> getUserneedGroup(String rouid) {
		return userNeedRelDao.selectByrouid(rouid);
	}

	@Override
	public void updataProstate(String rouid) {
		userNeedRelDao.updatalProstate(rouid);
	}
	
	@Override
	public int insertSaleNeed(BsSaleNeed req) {
		// TODO Auto-generated method stub
		return needSelfDao.insertSaleNeed(req);
	}
	@Override
	public int deleteSaleNeed(String rouid) {
		// TODO Auto-generated method stub
		return needSelfDao.deleteSaleNeed(rouid);
	}
	@Override
	public List<BsUserNeedRel> getAllneedGroup(String rouid){
		return userNeedRelDao.getAllUserneedGroup(rouid);
		
	}
	@Override
	public List<BsUserNeedRel> getPaname(String paraid){
		return userNeedRelDao.getPaname(paraid);
	}
	@Override
	public List<BsUserNeedRel> selectUserRemark(String rouid){ 
		return userNeedRelDao.selectUserRemark(rouid);
	}
	@Override
	public String selectProGroupNoByUserNo(String userNo) {
		// TODO Auto-generated method stub
		return needDao.selectProGroupNoByUserNo(userNo);
	}
	//上线数据
	@Override
	public List<BsOnlineNeed> selectBsOnlineNeedById(String needid) {
		// TODO Auto-generated method stub
		return needSelfDao.selectBsOnlineNeedById(needid);
	}
	@Override
	public int insertBsOnlineNeed(BsOnlineNeed req) {
		// TODO Auto-generated method stub
		return needSelfDao.insertBsOnlineNeed(req);
	}
	@Override
	public int deleteBsOnlineNeed(String rouid) {
		// TODO Auto-generated method stub
		return needSelfDao.deleteBsOnlineNeed(rouid);
	}

	@Override
	public List<FaceToFace> selectFace(FaceToFace req) {
		// TODO Auto-generated method stub
		return faceDao.selectFace(req);
	}
	@Override
	public List<FaceToFace> selectFacePage(FaceToFace req) {
		// TODO Auto-generated method stub
		return faceDao.selectFacePage(req);
	}
	@Override
	public int selectFaceCount(FaceToFace req) {
		// TODO Auto-generated method stub
		return faceDao.selectFaceCount(req);
	}

	@Override
	public List<BsNeedInfor> selectGoalAndReality(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectGoalAndReality(req);
	}
	@Override
	public List<BsNeedInfor> selectAllTeamIncome(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectAllTeamIncome(req);
	}
	
	@Override
	public List<BsNeedInfor> selectGoalAndGroup() {
		// TODO Auto-generated method stub
		return needSelfDao.selectGoalAndGroup();
	}
	@Override
	public List<BsNeedInfor> selectAllGroupIncome() {
		// TODO Auto-generated method stub
		return needSelfDao.selectAllGroupIncome();
	}
	
	@Override
	public List<BsNeedInfor> selectCurMonthList(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectCurMonthList(req);
	}
	@Override
	public List<BsNeedInfor> selectGoalAndRealityTeam(BsNeedInfor req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectGoalAndRealityTeam(req);
	}
	@Override
	public int insertBsNeedStage(BsNeedStage req) {
		// TODO Auto-generated method stub
		return needSelfDao.insertBsNeedStage(req);
	}
	@Override
	public List<BsNeedStage> selectBsNeedStage(BsNeedStage req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectBsNeedStage(req);
	}
	@Override
	public int updateBsNeedStage(BsNeedStage req) {
		// TODO Auto-generated method stub
		return needSelfDao.updateBsNeedStage(req);
	}
	@Override
	public int updateBsNeedStageOld(BsNeedStage req) {
		// TODO Auto-generated method stub
		return needSelfDao.updateBsNeedStageOld(req);
	}
	@Override
	public int updateBsNeedStageNew(BsNeedStage req) {
		// TODO Auto-generated method stub
		return needSelfDao.updateBsNeedStageNew(req);
	}
	
	
	@Override
	public int insertteamgoal(BsGoal req) {
		// TODO Auto-generated method stub
		return needSelfDao.insertteamgoal(req);
	}
	@Override
	public int insertgoal(BsGoal req) {
		// TODO Auto-generated method stub
		return needSelfDao.insertgoal(req);
	}
	@Override
	public List<BsGoal> selectteamgoal(BsGoal req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectteamgoal(req);
	}
	@Override
	public List<BsGoal> selectgoal(BsGoal req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectgoal(req);
	}
	@Override
	public int updategoal(BsGoal req) {
		// TODO Auto-generated method stub
		return needSelfDao.updategoal(req);
	}
	@Override
	public List<BsGoal> selectteamgoalsum(BsGoal req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectteamgoalsum(req);
	}
	@Override
	public int deleteteamgoal(String rouid) {
		// TODO Auto-generated method stub
		return needSelfDao.deleteteamgoal(rouid);
	}
	@Override
	public int insertHisStage(BsNeedStage req) {
		// TODO Auto-generated method stub
		return needSelfDao.insertHisStage(req);
	}
	@Override
	public List<NeedConversion> selectNeedConversion(NeedConversion req) {
		// TODO Auto-generated method stub
		return needSelfDao.selectNeedConversion(req);
	}
	
	@Override
	public List<NeedConversion> selectConversion() {
		// TODO Auto-generated method stub
		return needSelfDao.selectConversion();
	}

}
